/************************************************************************
 File:			Ethernet.h
 Author:		Justin England
 Class:			CSC 470
 Instructor:	Dr. Penaloza
 Date:			
 Description:	Header file to define ethernet class
 
 
 Known bugs/missing features:
 
 Modifications:
 Date                Comment            
 ----    ------------------------------------------------
 ************************************************************************/

#ifndef _ETHERNET_H_
#define _ETHERNET_H_

#include <QtGui>
#include "Master.h"

enum etherState					// state defines for the ethernet
{
	Idle,						// ethernet idle
        Busy,						// ethernet busy
        Collision
};

struct etherNetStruct			// params for the ethernet simulation
{
	etherState	currentState;	// current ethernet state
	int			masters;		// number of masters conected to ethernet
	int			packets;		// total number of packets processed
	int			collisions;		// total number of collisions
        int                     minPacketSize;
        int                     maxPacketSize;
        int                     speed;
};


class Master;					// pre-declare the master object


// class definition of the ethernet

class Ethernet : public QWidget
{
	Q_OBJECT
	
public:
	
        Ethernet(QWidget *parent);
	~Ethernet();
	
        bool	isBusy(int);			// check if ethernet is busy
	bool	acceptPacket(int, int);	// ask ethernet to accept packet
	void	putOnEthernet(int);		// put packet on ethernet

private slots:
	
        void	start(int, int, int, int);			// start the masters on ethernet
        void	stop(void);				// stop the masters on ethernet /** NEEDS TO BE IMPLEMENTED
        void    freeEthernet();
private:
		
	etherNetStruct		theNet;			// structure defines the current network
	QList<Master *>		netMasters;		// list of pointers to master objects
	QList<QThread *>	masterThreads;	// list of pointers to master's threads
	QList<int>			dataPacket;		// packet queue on the ethernet
	QMutex				packetMutex;	// mutex to protect dataPacket queue
        int currentSender;
        int currentReceiver;

signals:
        void enetStatusSignal( int );
        void masterActionSignal( int , int );

};


#endif /* _ETHERNET_H_ */
